//
//  FriendRootController.swift
//  SwitfTest
//
//  Created by runone02 on 2018/12/28.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

import UIKit

class FriendRootController: BaseViewController,UICollectionViewDataSource,UICollectionViewDelegate {
    var backColletionview:UICollectionView?
    
    lazy var dataArray = NSMutableArray()
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white
        //添加数据源
        self.dataArray = ["多选标签","各种图表类型","选择提示框","验证码输入框","扫描w二维码","生成二维码","识别图片二维码"]
        self.ceateCollectionView()
    }
    
    //布局collectionView
    func ceateCollectionView(){
        let layout = WaterFlow.init()    //自定义
        layout.layout(dataA: self.dataArray, coumns: 5, marginTop: 10, marginLeft: 10, marginbottom: 10, marginRight: 10, magrinMinH: 10, marginMinW: 10)
        
//        let layout = UICollectionViewFlowLayout.init()
//        layout.itemSize = CGSize(width: 60, height: 60)
//        layout.minimumLineSpacing = 5
//        layout.minimumInteritemSpacing = 5
//        layout.scrollDirection = .vertical
        
//        layout.sectionInset = UIEdgeInsets.init(top: 5, left: 5, bottom: 5, right: 5)   //设置间距
        
        // 设置分区头视图和尾视图宽高
//        layout.headerReferenceSize = CGSize.init(width: SCREEN_WIDTH, height: 10)
//        layout.footerReferenceSize = CGSize.init(width: SCREEN_WIDTH, height: 10)
        
        let collectionview = UICollectionView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT), collectionViewLayout: layout)

        collectionview.backgroundColor = UIColor.white
        self.backColletionview = collectionview
   
        self.view.addSubview(self.backColletionview!)
        self.backColletionview?.dataSource = self
        self.backColletionview?.delegate = self
        self.backColletionview?.register(FriendRootCell.self, forCellWithReuseIdentifier: "mycell")
    }
    
    /// item个数
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.dataArray.count
    }
  
    /// item内容
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell:FriendRootCell = backColletionview?.dequeueReusableCell(withReuseIdentifier: "mycell", for: indexPath) as! FriendRootCell
        let r = (CGFloat)(arc4random_uniform(255) + 1)/255.0
        let g = (CGFloat)(arc4random_uniform(255) + 1)/255.0
        let b = (CGFloat)(arc4random_uniform(255) + 1)/255.0
        cell.backgroundColor = UIColor(red: r, green: g, blue: b, alpha: 1)
        cell.fridendLabel.text = self.dataArray[indexPath.row] as? String
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if (indexPath.row == 0 ) {//搜索标签
            navigationController?.pushViewController(RulerViewController(), animated: true)
        }
        else if (indexPath.row == 1 ){//各种图表

            navigationController?.pushViewController(MainVC(), animated: true)
        }
        else if(indexPath.row == 2){   //加载数据提示框
            
            navigationController?.pushViewController(CueSelectionViewController(), animated: true)
        }
        else if(indexPath.row == 3){  //验证码输入框
            
            navigationController?.pushViewController(codeInputViewController(), animated: true)
        }
        else if(indexPath.row == 4){  //扫描w二维码
           navigationController?.pushViewController(ScanCodeViewController(), animated: true)
        }
        else if (indexPath.row == 5){   //生成二维码
            navigationController?.pushViewController(CreateQRCodeViewController(), animated:true)
        }
        else if (indexPath.row == 6){
           
        }
        
        else{
            
        }
    }
    
  
}
